
/*
 * @Date: 2024-11-22 10:06:39
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2025-02-18 13:59:39
 * @Description: 数据列表
 */
import { useDbSource } from '@hp/hooks/useDbSource.js'
import { defDataSource } from '@hp/panels/cfg.js'

const { loadDataCols } = useDbSource()

export default {
  // 组件
  component: () => import("./DataList.vue"),
  // 类型
  type: 'datalist',
  // 名称
  name: '数据列表',
  // 图标或图片
  icon: 'pi/data-list.png',
  // 初始配置
  schema: {
    // 面板名称
    label: '',
    // 描述
    desc: '',
    // 默认值
    defaultValue: [],
    // 数据源配置
    ...defDataSource,
    // 列设置
    columnList: []
  },
  // 大小定位
  layout: {
    i: '',
    x: '',
    y: '',
    w: 60,
    h: 24,
    minW: 24,
    minH: 12,
    maxW: 120,
    maxH: 72,
    static: false,
  },
  // 配置
  config: [
    {
      config: {
        label: '基础配置'
      },
      children: [
        {
          type: 'input',
          field: 'desc',
          label: '描述',
          compProps: {
          }
        },
      ]
    },
    {
      config: {
        label: '数据配置'
      },
      children: [
        {
          type: 'input-dbsource',
          field: 'dataSource',
          label: '数据源',
          noForm: false,
          compProps: {
          }
        },
      ]
    },
    {
      config: {
        label: '列表设置'
      },
      children: [
        {
          type: 'input-cards',
          field: 'columnList',
          label: '列表设置',
          noForm: true,
          compProps: {
          },
          children: [
            {
              type: "input",
              label: "名称",
              field: "columnList.title",
              compProps: {
              }
            },
            {
              type: "select",
              label: "字段",
              field: "columnList.field",
              compProps: {
                getUpConfig ({ schema }) {
                  return {
                    options: loadDataCols(schema)
                  }
                }
              }
            },
            {
              type: "number",
              label: "宽度",
              field: "columnList.width",
              compProps: {
                defaultValue: 0
              }
            },
            {
              type: "select",
              label: "对齐",
              field: "columnList.align",
              compProps: {
                options: [
                  { label: '居左', value: 'left' },
                  { label: '居中', value: 'center' },
                  { label: '居右', value: 'right' }
                ]
              }
            },
          ]
        },
      ]
    }
  ]
}